package cn.tedu.base.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

public class HashPasswordUtil {
    /**
     * 盐值
     */
    private static final String PWTRUE="PASSWORD!Q2W#E$RW";

    private static final String ALGORITHM = "SHA-256";

    public static String hashPassword(String password) {
        try {
            MessageDigest digest = MessageDigest.getInstance(ALGORITHM);
            byte[] saltedPassword = (PWTRUE + password).getBytes();
            byte[] hashedBytes = digest.digest(saltedPassword);
            return Base64.getEncoder().encodeToString(hashedBytes);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("Algorithm not supported", e);
        }
    }


}
